<?php

# http://projects:8081/cdapp-2kt-api/api/capacity_params.php

include_once '_portal.php';

if (isset($post->key) && isset($post->value)) {
  $value_json = json_stringify($post->value);
  $sql = "UPDATE `2kt_capacity_params` SET `value`='{$value_json}' WHERE `name`='{$post->key}'";
  $result = exec_sql($sql);
  output(['result' => $result]);
} else {
  $sql = "SELECT * FROM `2kt_capacity_params`";
  $res = exec_sql($sql);
  $params = [];
  foreach ($res as $cell) {
    $params[$cell['name']] = json_parse($cell['value']);
  }
  output($params);
}